using System;
using System.Data;
using System.Configuration;
using System.IO;
using Doc.Xroad.Eu;
using Doc.Xroad.Eu.Headers;
using Doc.Xroad.Eu.Messages;
using Xtee.Core.Adapter.Service;
using Xtee.Core.Envelope;
using Xtee.Core.Envelope.Header;
using Xtee.XteeAdapter.Doc;

namespace DocumentServingApplication.Services
{
    public class GetDocumentListing : GetDocumentListServiceHandler
    {
        public GetDocumentListResponse ProcessRequest(GetDocumentListRequest input, GetDocumentListInputHeader header)
        {
            var dirinfo = new DirectoryInfo(Configurator.GetConfig().Storage.TempRoot);
            var resp = new GetDocumentListResponse();

            FileInfo[] fi = dirinfo.GetFiles();
            for (int x = 0; x <= fi.Length - 1; x++)
            {
                if (fi[x].Extension == ".eml" || fi[x].Name == "log-file.txt")
                    continue;
                resp.AllDocuments.Add(new Document(fi[x].Name, null));
            }

            return resp;
        }
    }
}
